﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

namespace _2011DBProject
{
    public partial class Character : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!((Session["USER"]) == null) || !((Session["SERVER"]) == null))
            {
                lblServer.Text = (Session["SERVER"]).ToString();
                lblAccount.Text = (Session["USER"]).ToString();
                Label templbl = (Label)(DataList1.Controls[0].Controls[1]).FindControl("lblDLServer");
                lblServer.Text = templbl.Text;
            }
            else
                Response.Redirect("default.aspx?isNoSession=1");

            btnHb.Attributes.Add("onClick", "return confirm('정말로 삭제하시겠습니까?');");
        }       

        //protected void gvCharacter_SelectedIndexChanged(object sender, EventArgs e)
        //{
        //    lblCharac.Text = gvCharacter.DataKeys[gvCharacter.SelectedIndex].Value.ToString();
        //    Session.Add("CHARACTER_NAME", lblCharac.Text);
        //    Settings.StrCharacterName = lblCharac.Text;
        //    Button1.Visible = true;
        //}

        protected void Button1_Click(object sender, EventArgs e)
        {
            Response.Redirect("Channel.aspx");
        }

        protected void Button2_Click(object sender, EventArgs e)
        {
            Response.Redirect("MakeCharacter.aspx");
        }

        protected void ImageButton1_Command(object sender, CommandEventArgs e)
        {
            Session.Add("CHARACTER_NAME", e.CommandArgument.ToString());
            Settings.strCharacterName = e.CommandArgument.ToString();
            string guildname = GetGuildName(Settings.strCharacterName);
            if (guildname != "")
            {
                Session.Add("GUILD_NAME", guildname);
                Settings.strGuildName = guildname;
            }
            Response.Redirect("Channel.aspx");
        }



        protected void btnGoLogout_onclick(object sender, EventArgs e)
        {
            Session.Clear();
            Response.Redirect("Default.aspx");
        }

        protected void btnGoServer_onclick(object sender, EventArgs e)
        {
            Response.Redirect("Server.aspx");
        }

        protected void btnLockerRoom_Click(object sender, EventArgs e)
        {
            Response.Redirect("LockerRoom.aspx");
        }

        protected string GetGuildName(string strCharacterName)
        {
            string r = "";
            try
            {
                System.Data.OracleClient.OracleConnection cnn = new System.Data.OracleClient.OracleConnection(Settings.strConnectionString);
                System.Data.OracleClient.OracleCommand command = new System.Data.OracleClient.OracleCommand("select guild_name from guild_member where SERVER_NO = '" + Settings.decServer + "' and CHARACTER_NAME = '" + Settings.strCharacterName + "'", cnn);
                cnn.Open();
                System.Data.OracleClient.OracleDataReader dr = command.ExecuteReader();
                if (dr.Read())
                {
                    r = dr.GetString(0);
                }
                cnn.Close();
                return r;
            }
            catch (Exception)
            {
                throw;
            }
        }

        protected void Button3_Command(object sender, CommandEventArgs e)
        {
            lbltmp.Text = e.CommandArgument.ToString();
            lblHl1.Visible = true;
            lblHl2.Visible = true;
            txtHt.Visible = true;
            btnHb.Visible = true;
        }

        protected void btnHb_Click(object sender, EventArgs e)
        {
            if (txtHt.Text == "지금삭제")
            {
                //DataSet1 ds = new DataSet1();

                DataSet1TableAdapters.CHARACTERTableAdapter taCharacter = new DataSet1TableAdapters.CHARACTERTableAdapter();
                taCharacter.Connection.ConnectionString = Settings.strConnectionString;
                DataSet1.CHARACTERDataTable dtCharacter = taCharacter.GetDataByServerNoCharacterName(Settings.decServer, lbltmp.Text);

                DataSet1.CHARACTERRow row = dtCharacter[0];

                row.TITLE_NO = 9;

                taCharacter.Update(dtCharacter);
                DataList2.DataBind();

                lblHl1.Visible = false;
                lblHl2.Visible = false;
                txtHt.Visible = false;
                btnHb.Visible = false;
            }

          
        }
    }
}
